<template>
  <div>
    <!-- 实销变更查询 -->
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      :labelWidth="110"
    ></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="qjhSalesChangeQuery"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :onRowSelectChange="selectChangeHandle"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls">
          <multiuse-button size="small" type="primary" :click="exportHandle">导 出</multiuse-button>
        </template>
      </FilterTable>
    </Spin>

    <Drawer
      :visible.sync="visible"
      :title="drawerTitle"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <SonModel :type="handleType" :rowData="formData" @close="emitCloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, exportExcel,exporturl } from '@/api/dealerSale/SalesSanagement/SalesChangeQuery';
import SonModel from './SonModel';
import { exportExcelFile } from '@/utils/index';

export default {
  name: 'SalesChangeQuery',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    this.conf = { show: '明细' };

    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: { xhrAbort: true },
      formData: {},
      visible: false,
      handleType: '',
      drawerTitle: '',
      exportLoading: false
    };
  },
  components: {
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    // 导出
    async exportHandle() {
       let json = Object.assign({}, { CODE: 'CODE_0000066' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
      //   confirmButtonText: '下载',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     this.exportLoading = true;

      //     exportExcel(this.fetchParams)
      //       .then(response => {
      //         exportExcelFile(response.data, '实销变更查询');
      //         this.exportLoading = false;
      //       })
      //       .catch(err => {
      //         console.log(err);
      //       });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: 'info',
      //       message: '已取消'
      //     });
      //   });
    },
    // 搜索
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    // 明细
    detailHandle(row) {
      this.handleType = 'show';
      this.formData = row;
      this.showHandler();
    },

    showHandler() {
      this.drawerTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    selectChangeHandle(row) {},
    seacherFun() {
      this.issearch = true;
    },

    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          maxlength: '',
          maxRows: 2
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入'
        },

        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'customerPhone',
          placeholder: '请输入'
        },
        {
          type: 'RANGE_DATE',
          label: '开票日期',
          fieldName: 'invoiceDateStart|invoiceDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
        {
          type: 'RANGE_DATE',
          label: '实销通过日期',
          fieldName: 'reportPassDateStart|reportPassDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
        {
          type: 'SELECT',
          label: '变更状态',
          fieldName: 'changeStatus',
          placeholder: '请选择',
          itemList: this.createDictList('6057')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '变更状态',
          dataIndex: 'changeStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6057'),
          render: props => {
            return <span>{this.createDictText(props.row.changeStatus, '6057')}</span>;
          }
        },
        {
          title: '变更时间',
          dataIndex: 'reportCreateDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '零售单号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '客户编号',
          dataIndex: 'customerNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'customerSex',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1002'),
          render: props => {
            return <span>{this.createDictText(props.row.customerSex, '1002')}</span>;
          }
        },
        {
          title: '手机号',
          dataIndex: 'mobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电话',
          dataIndex: 'phone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '使用人',
          dataIndex: 'userName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '使用人电话',
          dataIndex: 'userPhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '身份证号',
          dataIndex: 'cardNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '年龄',
          dataIndex: 'age', // TODO 9407
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('9407'),
          render: props => {
            return <span>{this.createDictText(props.row.age, '9407')}</span>;
          }
        },
        {
          title: '学历',
          dataIndex: 'education', // TODO 4049
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('4049'),
          render: props => {
            return <span>{this.createDictText(props.row.education, '4049')}</span>;
          }
        },
        {
          title: '户口类型',
          dataIndex: 'residenceType', // TODO 7062
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7062'),
          render: props => {
            return <span>{this.createDictText(props.row.residenceType, '7062')}</span>;
          }
        },
        {
          title: '职业',
          dataIndex: 'occupation', // TODO 1527
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1527'),
          render: props => {
            return <span>{this.createDictText(props.row.occupation, '1527')}</span>;
          }
        },
        {
          title: '邮编',
          dataIndex: 'zipCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '地址',
          dataIndex: 'linkAddress',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆形式',
          dataIndex: 'powerType', // TODO 6008
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6008'),
          render: props => {
            return <span>{this.createDictText(props.row.powerType, '6008')}</span>;
          }
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '公告号',
          dataIndex: 'noticeNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置名称',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装名称',
          dataIndex: 'optionName',
          align: 'center',
          width: 250,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimColorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '颜色',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '订单类型',
          dataIndex: 'orderType', // TODO 6026
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6026'),
          render: props => {
            return <span>{this.createDictText(props.row.orderType, '6026')}</span>;
          }
        },
        {
          title: '车牌号',
          dataIndex: 'plateNumber',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售顾问',
          dataIndex: 'salesManName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType', // TODO 1523
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: props => {
            return <span>{this.createDictText(props.row.customerType, '1523')}</span>;
          }
        },

        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '县区',
          dataIndex: 'districtName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实销建档日期',
          dataIndex: 'reportAddDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '实销通过日期',
          dataIndex: 'reportPassDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '生产日期',
          dataIndex: 'productDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '出库日期',
          dataIndex: 'stockOutData',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '入库日期',
          dataIndex: 'postingDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票号',
          dataIndex: 'invoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '交车日期',
          dataIndex: 'deliveryDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '市场指导价',
          dataIndex: 'basicPrice',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发动机',
          dataIndex: 'engineNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电机号',
          dataIndex: 'motorCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电池号',
          dataIndex: 'batteryNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '支付方式',
          dataIndex: 'payType', // TODO 6015
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6015'),
          render: props => {
            return <span>{this.createDictText(props.row.payType, '6015')}</span>;
          }
        },
        {
          title: '金融机构',
          dataIndex: 'financialInstitution', //TODO 9602
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('9602'),
          render: props => {
            return <span>{this.createDictText(props.row.financialInstitution, '9602')}</span>;
          }
        },
        {
          title: '期数',
          dataIndex: 'periodsNumber', // TODO 6061
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6061'),
          render: props => {
            return <span>{this.createDictText(props.row.periodsNumber, '6061')}</span>;
          }
        },
        {
          title: '上牌省份',
          dataIndex: 'plateProvinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '上牌城市',
          dataIndex: 'plateCityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆性质',
          dataIndex: 'vehicleType', // TODO 4103
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('4103'),
          render: props => {
            return <span>{this.createDictText(props.row.vehicleType, '4103')}</span>;
          }
        },
        {
          title: '是否大客户',
          dataIndex: 'isBigCustomerOrder', // TODO 1004
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isBigCustomerOrder, '1004')}</span>;
          }
        },
        {
          title: '大客户项目编号',
          dataIndex: 'majorContractNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否三方车辆',
          dataIndex: 'isTripartite', // TODO 1004
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isTripartite, '1004')}</span>;
          }
        },
        {
          title: '资金类型',
          dataIndex: 'accountTypeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '下线工厂',
          dataIndex: 'factoryName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '仓库',
          dataIndex: 'warehouseName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
